/**
 * @param {number[]} nums
 * @return {number}
 */
var removeDuplicates = function(nums) {
    var i,
        length = nums.length,
        diff = 0,
        count = 1;
    for(i=1;i<length;i++){
        if(nums[i] === nums[diff]){
            count++;
            if(count == 2){
                nums[++diff] = nums[i];
            }
        }
        else{
            nums[++diff] = nums[i];
            count=1;
        }
        //console.log(nums,"diff at "+diff,"nums[i]="+nums[i],"count"+count);
    }
    return diff+1;
};






var nums = [1,1,1,1,1,1,1,2,2,2,2,3,4,4,5,6,7];
console.log(nums);
var res = removeDuplicates(nums);
console.log(nums);
console.log(res);